const app = getApp();
var utils = require('../../../utils/utils.js')
// 定义一个全局变量保存从接口获取到的数据，以免重复请求接口
var resut; 
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showCover:false,
    currentTab:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    this.setData({
      id: options.bangdanId,
    })

    var url = 'http://127.0.0.1:8000/classify/' + options.bangdanId + '/'
    utils.myRequest({
      url: url,
      methods: 'GET',
      success: function (res) {
        console.log(res);
        resut = res;
        wx.setNavigationBarTitle({
          title: res.data.title
        })
        that.setData({
          result: res.data,
          list:res.data.navTitle
        })
      },
      fail: function () {

      }
    })
  },
  handleClick(e) {
    let currentTab = e.currentTarget.dataset.index;
    // 实现每一个tabbar切换对应内容的原理，根据每一个tabbar的index对应数组中的数据
    this.setData({
      currentTab,
      list: resut.data.navTitle[currentTab]
    })
  },
  pullDown:function(){
    var that = this;
    that.setData({
      showCover:true
    })
  },
  closeCover:function(){
    var that = this;
    that.setData({
      showCover:false
    })
  },
  CoverCheck:function(e){
    let currentTab = e.currentTarget.dataset.index;
    // 实现每一个tabbar切换对应内容的原理，根据每一个tabbar的index对应数组中的数据
    this.setData({
      currentTab,
      list: resut.data.navTitle[currentTab]
    })
    this.closeCover()
  },

  works: function (event){
    // 各分类的作品集
    var that = this;
    var works_id = event.currentTarget.dataset.id;
    utils.myRequest({
      url: 'http://127.0.0.1:8000/works/'+ works_id + '/',
      methods: 'GET',
      success: function (res) {
        console.log(res.data);
        that.setData({
          works_info: res.data,
        })
      },
      fail:function(){

      }
    })
  },
  details: function (event){
    var works_id = event.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/details/details?WorksId=' + works_id,
    })
  }
})
